import React from 'react';
import {
  FileTextOutlined,
  FileImageOutlined,
  FileOutlined,
  FolderOutlined,
  FileZipOutlined,
  FileUnknownOutlined,
  FilePdfOutlined,
  FileExcelOutlined,
  FileWordOutlined,
  FilePptOutlined,
  FileMarkdownOutlined,
  FileJpgOutlined,
  FileGifOutlined,
  CustomerServiceOutlined,
  VideoCameraOutlined
} from '@ant-design/icons';
import { FileType, FileIconProps } from '../../pages/backhub/filemgr/types';

const FileIcon: React.FC<FileIconProps> = ({ fileType, extension, size = 24 }) => {
  const iconStyle = {
    fontSize: size,
  };

  const getIconByExtension = (ext?: string) => {
    if (!ext) return <FileOutlined style={iconStyle} />;

    // 文档类型图标
    switch (ext.toLowerCase()) {
      case 'pdf':
        return <FilePdfOutlined style={iconStyle} />;
      case 'xlsx':
      case 'xls':
      case 'csv':
        return <FileExcelOutlined style={iconStyle} />;
      case 'docx':
      case 'doc':
        return <FileWordOutlined style={iconStyle} />;
      case 'pptx':
      case 'ppt':
        return <FilePptOutlined style={iconStyle} />;
      case 'md':
        return <FileMarkdownOutlined style={iconStyle} />;
      case 'jpg':
      case 'jpeg':
        return <FileJpgOutlined style={iconStyle} />;
      case 'png':
        return <FileImageOutlined style={iconStyle} />;
      case 'gif':
        return <FileGifOutlined style={iconStyle} />;
      case 'zip':
      case 'rar':
      case '7z':
      case 'tar':
      case 'gz':
        return <FileZipOutlined style={iconStyle} />;
      default:
        return null;
    }
  };

  const getIconByFileType = () => {
    switch (fileType) {
      case FileType.FOLDER:
        return <FolderOutlined style={iconStyle} />;
      case FileType.DOCUMENT:
        return getIconByExtension(extension) || <FileTextOutlined style={iconStyle} />;
      case FileType.IMAGE:
        return getIconByExtension(extension) || <FileImageOutlined style={iconStyle} />;
      case FileType.AUDIO:
        return <CustomerServiceOutlined style={iconStyle} />;
      case FileType.VIDEO:
        return <VideoCameraOutlined style={iconStyle} />;
      case FileType.ARCHIVE:
        return <FileZipOutlined style={iconStyle} />;
      case FileType.OTHER:
      default:
        return <FileUnknownOutlined style={iconStyle} />;
    }
  };

  return getIconByFileType();
};

export default FileIcon; 